package pta05;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class WordFrequencySort_pta553 {
	public static void main(String[] args){
	Map<String,Integer> mapword=new HashMap<String,Integer>();
	Scanner in=new Scanner(System.in);
	while(in.hasNext()) {
		String str=in.next();
        if(str.equals("!!!!!")) {
        	break;
        }
		else {
			if(mapword.containsKey(str)){
				mapword.put(str, mapword.get(str)+1);
			}
			else mapword.put(str,1);
		}
	}
	in.close();
	ArrayList<Map.Entry<String,Integer>> wordlist=new ArrayList<Map.Entry<String,Integer>>(mapword.entrySet());
	Collections.sort(wordlist,(o1,o2)->{
			if(o1.getValue()!=o2.getValue()){
				return o2.getValue()-o1.getValue();
			}
			else return o1.getKey().compareTo(o2.getKey());}
	);	
	System.out.println(mapword.size());
	for(int i=0;i<10;i++){
		System.out.println(wordlist.get(i));
	}
	}

	@Override
	public String toString() {
		return "WordFrequencySort_pta553 [toString()=" + super.toString() + "]";
	}
}
